package cn.xfdzx.android.apps.shop.activity.ruzhu;

import android.app.DatePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.google.gson.Gson;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.listener.OnResultCallbackListener;

import java.io.File;
import java.io.IOException;
import java.net.Proxy;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.apps.Constants;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.bean.IdCardBeen;
import cn.xfdzx.android.apps.shop.bean.LicenseImgBeen;
import cn.xfdzx.android.apps.shop.bean.Ruzhu_StepBean;
import cn.xfdzx.android.apps.shop.bean.Store_ruzhuBean;
import cn.xfdzx.android.apps.shop.bean.UploadImgBeen;
import cn.xfdzx.android.apps.shop.contract.Store_InfoContract;
import cn.xfdzx.android.apps.shop.presenter.Store_InfoPresenter;
import cn.xfdzx.android.apps.shop.util.GlideEngine;
import cn.xfdzx.android.apps.shop.util.ShopCarPopupWindow;
import cn.xfdzx.android.apps.shop.util.UtilsLog;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import static cn.xfdzx.android.apps.shop.apps.Constants.APP_TOKEN;

public class Shop_OwnerActivity extends BaseMvpActivity<Store_InfoPresenter> implements Store_InfoContract.View {
    public Context mContext;

    @BindView(R.id.ll_state)
    LinearLayout llState;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rl_title)
    RelativeLayout rlTitle;
    @BindView(R.id.tv_title_name)
    TextView tvTitleName;
    @BindView(R.id.ll_shop_photo)
    LinearLayout llShopPhoto;
    @BindView(R.id.zhengmian)
    ImageView zhengmian;
    @BindView(R.id.beimian)
    ImageView beimian;
    @BindView(R.id.rl_shop_photo)
    RelativeLayout rlShopPhoto;
    @BindView(R.id.zhenshixingming)
    EditText zhenshixingming;
    @BindView(R.id.ll_contacts_name)
    LinearLayout llContactsName;
    @BindView(R.id.changqiyouxiao)
    ImageView changqiyouxiao;
    @BindView(R.id.ll_qixian)
    LinearLayout llQixian;
    @BindView(R.id.gudingyouxiao)
    ImageView gudingyouxiao;
    @BindView(R.id.kaishishijian)
    TextView kaishishijian;
    @BindView(R.id.jieshushijian)
    TextView jieshushijian;
    @BindView(R.id.time)
    LinearLayout time;
    @BindView(R.id.ll_super_adm)
    LinearLayout llSuperAdm;
    @BindView(R.id.xinxitongbu)
    ImageView xinxitongbu;
    @BindView(R.id.tv_shuoming_money)
    TextView tvShuomingMoney;
    @BindView(R.id.guanlizhengmian)
    ImageView guanlizhengmian;
    @BindView(R.id.guanlibeimian)
    ImageView guanlibeimian;
    @BindView(R.id.rl_super_adm)
    RelativeLayout rlSuperAdm;
    @BindView(R.id.guanlixingming)
    EditText guanlixingming;
    @BindView(R.id.ll)
    LinearLayout ll;
    @BindView(R.id.shenfenzhenghaoma)
    EditText shenfenzhenghaoma;
    @BindView(R.id.ll_contacts_phone)
    LinearLayout llContactsPhone;
    @BindView(R.id.guanliyuanshouji)
    EditText guanliyuanshouji;
    @BindView(R.id.ll_super_admemail)
    LinearLayout llSuperAdmemail;
    @BindView(R.id.guanliyuanyouxiang)
    EditText guanliyuanyouxiang;
    @BindView(R.id.ll_super_admphone)
    LinearLayout llSuperAdmphone;
    @BindView(R.id.tv_yi_du)
    TextView tvYiDu;
    @BindView(R.id.hintxingming)
    TextView hintxingming;
    @BindView(R.id.hintguanliyuanxingming)
    TextView hintguanliyuanxingming;
    @BindView(R.id.hingguanliyuanzj)
    TextView hingguanliyuanzj;
    @BindView(R.id.hintguanliyuanshouji)
    TextView hintguanliyuanshouji;
    @BindView(R.id.hintguanliyuanyouxiang)
    TextView hintguanliyuanyouxiang;
    @BindView(R.id.addshenfenhaoma)
    EditText addshenfenhaoma;
    @BindView(R.id.ll_contacts_names)
    LinearLayout llContactsNames;
    @BindView(R.id.hintaddshenfenhaoma)
    TextView hintaddshenfenhaoma;
    private String storeid;
    protected Handler handler = new Handler();
    private String shenfenzhengmian = "", shenfenbeimian = "", guanliidzhengmian = "", guanliidfanmian = "";
    private ShopCarPopupWindow yearPopupWindow;
    int year, month, day;
    private String nyr_start = "";
    private String validTerm = "";//有效期
    private String nyr_end = "";
    private Calendar calendar;
    private int flag = 1;
    //存储页面上的日期选择器
    DatePicker datePicker;
    private IdCardBeen idCardBeen;
    private int temp = 1;
    private int t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0;
    String telRegex = "^((13[0-9])|(14[5,7,9])|(15[^4])|(18[0-9])|(17[0,1,3,5,6,7,8]))\\d{8}$";// "[1]"代表第1位为数字1，"[358]"代表第二位可以为3、5、8中的一个，"\\d{9}"代表后面是可以是0～9的数字，有9位。
    String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";

    @Override
    public int getLayoutId() {
        return R.layout.activity_shop__owner;
    }

    @Override
    public void initView() {
        mPresenter = new Store_InfoPresenter();
        mPresenter.attachView(this);

        mPresenter.getStep_Ruzhu("three");
        mContext=this;
    }


    @Override
    public void getStateType(Store_ruzhuBean bean) {
    }

    @Override
    public void getRuzhuStep(Ruzhu_StepBean bean) {
        Intent intent = getIntent();
        storeid = intent.getStringExtra("stoid");
        Log.e("zhuangtai", storeid + "");
        setText(bean);

    }

    private void setText(Ruzhu_StepBean bean) {

        RoundedCorners roundedCorners = new RoundedCorners(10);
        //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
        Glide.with(mContext).load(bean.getData().getIdcard_front_img()).apply(options.transform(new CenterCrop(), roundedCorners)).into(zhengmian);

        Glide.with(mContext).load(bean.getData().getIdcard_back_img()).apply(options.transform(new CenterCrop(), roundedCorners)).into(beimian);
        shenfenzhengmian = bean.getData().getIdcard_front_img();
        shenfenbeimian = bean.getData().getIdcard_back_img();
        zhenshixingming.setText(bean.getData().getIdcard_name());
        addshenfenhaoma.setText(bean.getData().getIdcard());
        if (bean.getData().getIdcard_invalid_time().contains("长期") || bean.getData().getIdcard_invalid_time() == null) {
            time.setVisibility(View.GONE);
            changqiyouxiao.setImageResource(R.drawable.circle_ok);
            gudingyouxiao.setImageResource(R.drawable.circle);
            temp = 1;
        } else {
            time.setVisibility(View.VISIBLE);
            changqiyouxiao.setImageResource(R.drawable.circle);
            gudingyouxiao.setImageResource(R.drawable.circle_ok);
            temp = 2;
        }
        kaishishijian.setText(bean.getData().getIdcard_take_effect_time());
        jieshushijian.setText(bean.getData().getIdcard_invalid_time());
        Glide.with(mContext).load(bean.getData().getAdmin_idcard_front_img()).apply(options.transform(new CenterCrop(), roundedCorners)).into(guanlizhengmian);
        Glide.with(mContext).load(bean.getData().getAdmin_idcard_back_img()).apply(options.transform(new CenterCrop(), roundedCorners)).into(guanlibeimian);
        guanliidzhengmian = bean.getData().getAdmin_idcard_front_img();
        guanliidfanmian = bean.getData().getAdmin_idcard_back_img();
        guanlixingming.setText(bean.getData().getAdmin_idcard_name());
        shenfenzhenghaoma.setText(bean.getData().getAdmin_idcard());
        guanliyuanshouji.setText(bean.getData().getAdmin_phone());
        guanliyuanyouxiang.setText(bean.getData().getAdmin_email());

    }

    @Override
    public void oneLicenseImgSuccess(LicenseImgBeen bean) {
    }

    @Override
    public void onIdCardSuccess(IdCardBeen bean) {

        setShibie(bean);
        idCardBeen = new IdCardBeen();

        idCardBeen = bean;

    }

    @Override
    public void onIdCardSuccessguanli(IdCardBeen bean) {
        setshibieguanli(bean);
    }

    private void setshibieguanli(IdCardBeen bean) {
        guanlixingming.setText(bean.getData().getName());
        shenfenzhenghaoma.setText(bean.getData().getIdNo());

    }

    private void setShibie(IdCardBeen bean) {
        zhenshixingming.setText(bean.getData().getName());
        addshenfenhaoma.setText(bean.getData().getIdNo());
        ValidChange(bean.getData().getValidityPeriod());
        if (bean.getData().getValidityPeriod().contains("长期")) {
            changqiyouxiao.setImageResource(R.drawable.circle_ok);
            gudingyouxiao.setImageResource(R.drawable.circle);
            time.setVisibility(View.GONE);
            temp = 1;
        } else {
            time.setVisibility(View.VISIBLE);
            changqiyouxiao.setImageResource(R.drawable.circle);
            gudingyouxiao.setImageResource(R.drawable.circle_ok);
            temp = 2;
        }
    }

    private void ValidChange(String validTerm) {
        //2017年02月07日至2037年02月06日
        String[] splitAddress = validTerm.split("-");
        String kaishinian = splitAddress[0].replaceAll("\\.", "-");
        String kaishiyue = kaishinian.replaceAll("\\.", "-");
        String kaishiri = kaishiyue.replaceAll("\\.", "");
        kaishishijian.setText(kaishiri);
        kaishishijian.setTextColor(getResources().getColor(R.color.color_333333));

        String jieshunian = splitAddress[1].replaceAll("\\.", "-");
        String jieshuyue = jieshunian.replaceAll("\\.", "-");
        String jieshuri = jieshuyue.replaceAll("\\.", "");
        jieshushijian.setText(jieshuri);
        jieshushijian.setTextColor(getResources().getColor(R.color.color_333333));


    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }


    @OnClick({R.id.iv_back, R.id.zhengmian, R.id.beimian, R.id.changqiyouxiao, R.id.gudingyouxiao, R.id.kaishishijian, R.id.jieshushijian, R.id.xinxitongbu, R.id.guanlizhengmian, R.id.guanlibeimian, R.id.tv_yi_du})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.zhengmian:
                selectImage(zhengmian, 0);
                break;
            case R.id.beimian:
                selectImage(beimian, 0);
                break;
            case R.id.changqiyouxiao:
                changqiyouxiao.setImageResource(R.drawable.circle_ok);
                gudingyouxiao.setImageResource(R.drawable.circle);
                time.setVisibility(View.GONE);
                temp = 1;
                break;
            case R.id.gudingyouxiao:
                time.setVisibility(View.VISIBLE);
                changqiyouxiao.setImageResource(R.drawable.circle);
                gudingyouxiao.setImageResource(R.drawable.circle_ok);
                temp = 2;
                break;
            case R.id.kaishishijian:
                popupWindow(1);
                break;
            case R.id.jieshushijian:
                popupWindow(2);
                break;
            case R.id.xinxitongbu:
                if (flag == 1) {
                    xinxitongbu.setImageResource(R.drawable.circle_ok);
                    flag = 2;
                    setTongbu();
                } else {
                    xinxitongbu.setImageResource(R.drawable.circle);
                    flag = 1;
                }
                break;
            case R.id.guanlizhengmian:
                selectImage(guanlizhengmian, 1);

                break;
            case R.id.guanlibeimian:
                selectImage(guanlibeimian, 1);

                break;
            case R.id.tv_yi_du:
                if (temp != 0) {
                    t1 = 1;
                }
                if (shenfenzhengmian.equals("") == false) {
                    t2 = 1;
                }
                if (shenfenbeimian.equals("") == false) {
                    t3 = 1;
                }
                if (zhenshixingming.getText().toString().equals("") || zhenshixingming.getText().toString() == null) {
                    hintxingming.setVisibility(View.VISIBLE);
                } else {
                    hintxingming.setVisibility(View.INVISIBLE);
                    t4 = 1;
                }
                if (addshenfenhaoma.getText().toString().equals("") || addshenfenhaoma.getText().toString() == null) {
                    hintaddshenfenhaoma.setVisibility(View.VISIBLE);
                } else {
                    hintaddshenfenhaoma.setVisibility(View.INVISIBLE);
                    t5 = 1;
                }
                if (kaishishijian.getText().toString() == null || kaishishijian.getText().toString().equals("")) {
                    t6 = 0;
                } else {
                    t6 = 1;
                }
                if (jieshushijian.getText().toString() == null || jieshushijian.getText().toString().equals("")) {
                    t7 = 0;
                } else {
                    t7 = 1;
                }
                if (guanliidzhengmian.equals("") == false) {
                    t8 = 1;
                }
                if (guanliidfanmian.equals("") == false) {
                    t9 = 1;
                }
                if (guanlixingming.getText().toString() == null || guanlixingming.getText().toString().equals("")) {
                    t10 = 0;
                    hintguanliyuanxingming.setVisibility(View.VISIBLE);
                } else {
                    hintguanliyuanxingming.setVisibility(View.INVISIBLE);
                    t10 = 1;
                }
                if (shenfenzhenghaoma.getText().toString() == null || shenfenzhenghaoma.getText().toString().equals("")) {
                    hingguanliyuanzj.setVisibility(View.VISIBLE);
                    t11 = 0;
                } else {
                    hingguanliyuanzj.setVisibility(View.INVISIBLE);
                    t11 = 1;
                }
                if (guanliyuanshouji.getText().toString() == null || guanliyuanshouji.getText().toString().equals("")) {
                    hintguanliyuanshouji.setVisibility(View.VISIBLE);
                    t12 = 0;
                } else {
                    hintguanliyuanshouji.setVisibility(View.INVISIBLE);
                    t12 = 1;
                }
                if (guanliyuanyouxiang.getText().toString() == null || guanliyuanyouxiang.getText().toString().equals("")) {
                    hintguanliyuanyouxiang.setVisibility(View.VISIBLE);
                    t13 = 0;
                } else {
                    hintguanliyuanyouxiang.setVisibility(View.INVISIBLE);
                    t13 = 1;
                }
                if (guanliyuanshouji.getText().toString().matches(telRegex) == true) {
                    t14 = 1;
                }
                if (guanliyuanyouxiang.getText().toString().matches(check) == true) {
                    t15 = 1;
                }

                if (t1 == 1 && t2 == 1 && t3 == 1 && t4 == 1 && t5 == 1 && t6 == 1 && t7 == 1 && t8 == 1 && t9 == 1 && t10 == 1 && t11 == 1 &&
                        t12 == 1 && t13 == 1 && t14 == 1 && t15 == 1) {
                    HashMap<String, Object> map = new HashMap<>();
                    map.put("step", "three");
                    map.put("store_id", storeid);
                    map.put("idcard_front_img", shenfenzhengmian);
                    map.put("idcard_back_img", shenfenbeimian);
                    map.put("idcard_name", zhenshixingming.getText());
                    map.put("idcard", addshenfenhaoma.getText());
                    map.put("idcard_take_effect_time", kaishishijian.getText());
                    map.put("idcard_invalid_time", jieshushijian.getText());
                    if (flag == 2) {
                        map.put("admin_idcard_front_img", shenfenzhengmian);
                        map.put("admin_idcard_back_img", shenfenbeimian);
                    } else {
                        map.put("admin_idcard_front_img", guanliidzhengmian);
                        map.put("admin_idcard_back_img", guanliidfanmian);
                    }
                    map.put("admin_idcard_name", guanlixingming.getText());
                    map.put("admin_idcard", shenfenzhenghaoma.getText());
                    map.put("admin_phone", guanliyuanshouji.getText());
                    map.put("admin_email", guanliyuanyouxiang.getText());
                    Log.e("appkok", APP_TOKEN);
                    Log.e("ceasd", map.toString());

                    mPresenter.getState_Ruzhu(map);
                    Intent intent = new Intent(this, InformationActivity.class);
                    startActivity(intent);
                } else if (t14 != 1) {
                    if (guanliyuanshouji.getText().toString().equals("") == false && guanliyuanshouji.getText().toString() != null) {
                        Toast.makeText(mContext, "手机号输入错误！", Toast.LENGTH_SHORT).show();
                    }
                } else if (t15 != 1) {
                    if (guanliyuanyouxiang.getText().toString().equals("") == false && guanliyuanyouxiang.getText().toString() != null) {
                        Toast.makeText(mContext, "邮箱格式输入错误！", Toast.LENGTH_SHORT).show();
                    }
                } else {
                    Toast.makeText(mContext, "请确认信息输入完整后提交！", Toast.LENGTH_SHORT).show();
                }

                break;
        }
    }

    private void setTongbu() {
        RoundedCorners roundedCorners = new RoundedCorners(10);
        //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
        if (idCardBeen.getData() != null) {
            Glide.with(mContext).load(shenfenzhengmian).apply(options.transform(new CenterCrop(), roundedCorners)).into(guanlizhengmian);
            Glide.with(mContext).load(shenfenbeimian).apply(options.transform(new CenterCrop(), roundedCorners)).into(guanlibeimian);
            guanliidzhengmian = shenfenzhengmian;
            guanliidfanmian = shenfenbeimian;
            guanlixingming.setText(idCardBeen.getData().getName());
            shenfenzhenghaoma.setText(idCardBeen.getData().getIdNo());
        }

    }

    private void editListen(EditText ett, TextView textView) {

        ett.addTextChangedListener(new TextWatcher() {
            @Override
            public void afterTextChanged(Editable s) {

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                                      int count) {

                if (s.length() >= 1) {
                    textView.setVisibility(View.GONE);
                } else {
                    textView.setVisibility(View.VISIBLE);
                }
            }

        });
    }

    public void selectImage(ImageView imageView, int i) {
        PictureSelector.create(this)
                .openGallery(PictureMimeType.ofImage()).maxSelectNum(1)
                .loadImageEngine(GlideEngine.createGlideEngine())
                .minSelectNum(1).imageSpanCount(4)
                .selectionMode(PictureConfig.SINGLE)
                .compress(true)
                .minimumCompressSize(1000)
                .compressQuality(60)
                .isCamera(true)
                .previewImage(true)
                .forResult(new OnResultCallbackListener<LocalMedia>() {
                    @Override
                    public void onResult(List<LocalMedia> result) {
                        // onResult Callback
                        if (result.size() != 0) {
                            UtilsLog.error("dizhi", result.get(0).getCompressPath());
//                                    new File(result.get(0).getPath())
//                                    mPresenter.upload(new File(result.get(0).getPath()));
                            showLoading();
                            if (i == 0) {
                                upLoadFiles(Constants.BASE_URL + "/addons/shimmer_liveshop/index.php/api/6/3/plugin/merch/common/apply/uploadImg", new File(result.get(0).getCompressPath()), new XFDShopInActivity.ConnectListener() {
                                    @Override
                                    public void connectSuccess(String result) {
                                        handler.post(new Runnable() {
                                            @Override
                                            public void run() {
                                                hideLoading();
                                                try {
                                                    Gson gson = new Gson();
                                                    UploadImgBeen uploadImgBeen = gson.fromJson(result, UploadImgBeen.class);
                                                    if (uploadImgBeen.getErrno().equals("200")) {

                                                        RoundedCorners roundedCorners = new RoundedCorners(10);
                                                        //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
                                                        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
                                                        Glide.with(mContext).load(uploadImgBeen.getData().getSrc()).apply(options.transform(new CenterCrop(), roundedCorners)).into(imageView);
                                                        if (imageView == zhengmian) {

                                                            shenfenzhengmian = uploadImgBeen.getData().getSrc();

                                                        } else if (imageView == beimian) {
                                                            shenfenbeimian = uploadImgBeen.getData().getSrc();
                                                            mPresenter.idCardSubmit(shenfenzhengmian, shenfenbeimian);
                                                        }


                                                    } else {
                                                        Toast.makeText(mContext, uploadImgBeen.getMessage(), Toast.LENGTH_SHORT).show();
                                                    }
                                                } catch (Exception e) {
                                                    Toast.makeText(mContext, "上传失败", Toast.LENGTH_SHORT).show();

                                                }
                                            }
                                        });

                                    }

                                    @Override
                                    public void connectFailed(String error) {
                                        handler.post(new Runnable() {
                                            @Override
                                            public void run() {
                                                hideLoading();

                                            }
                                        });
                                    }
                                });

                            } else {
                                upLoadFiles(Constants.BASE_URL + "/addons/shimmer_liveshop/index.php/api/6/3/plugin/merch/common/apply/uploadImg", new File(result.get(0).getCompressPath()), new XFDShopInActivity.ConnectListener() {
                                    @Override
                                    public void connectSuccess(String result) {
                                        handler.post(new Runnable() {
                                            @Override
                                            public void run() {
                                                hideLoading();
                                                try {
                                                    Gson gson = new Gson();
                                                    UploadImgBeen uploadImgBeen = gson.fromJson(result, UploadImgBeen.class);
                                                    if (uploadImgBeen.getErrno().equals("200")) {

                                                        RoundedCorners roundedCorners = new RoundedCorners(10);
                                                        //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
                                                        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
                                                        Glide.with(mContext).load(uploadImgBeen.getData().getSrc()).apply(options.transform(new CenterCrop(), roundedCorners)).into(imageView);

                                                        if (imageView == guanlizhengmian) {
                                                            guanliidzhengmian = uploadImgBeen.getData().getSrc();
                                                        } else if (imageView == guanlibeimian) {
                                                            guanliidfanmian = uploadImgBeen.getData().getSrc();
                                                            mPresenter.onIdCardSuccessguanli(guanliidzhengmian, guanliidfanmian);
                                                        }


                                                    } else {
                                                        Toast.makeText(mContext, uploadImgBeen.getMessage(), Toast.LENGTH_SHORT).show();
                                                    }
                                                } catch (Exception e) {
                                                    Toast.makeText(mContext, "上传失败", Toast.LENGTH_SHORT).show();

                                                }
                                            }
                                        });

                                    }

                                    @Override
                                    public void connectFailed(String error) {
                                        handler.post(new Runnable() {
                                            @Override
                                            public void run() {
                                                hideLoading();

                                            }
                                        });
                                    }
                                });

                            }
                        }
                    }

                    @Override
                    public void onCancel() {
                        // onCancel Callback
                    }
                });
    }

    public void upLoadFiles(final String url, File file,
                            final XFDShopInActivity.ConnectListener connectListener) {
        OkHttpClient okHttpClient = new OkHttpClient.Builder().proxy(Proxy.NO_PROXY).connectTimeout(60 * 1000, TimeUnit.MILLISECONDS)
                .readTimeout(5 * 60 * 1000, TimeUnit.MILLISECONDS)
                .writeTimeout(5 * 60 * 1000, TimeUnit.MILLISECONDS)
                .build();
        MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder();
        multipartBodyBuilder.setType(MultipartBody.FORM);
        //遍历map中所有参数到builder
        multipartBodyBuilder.addFormDataPart("file", file.getName(), RequestBody.create(MediaType.parse("image/png"), file));
        //构建请求体
        RequestBody requestBody = multipartBodyBuilder.build();
        Request.Builder RequestBuilder = new Request.Builder();
        RequestBuilder.url(url);// 添加URL地址
        RequestBuilder.post(requestBody);
        RequestBuilder.addHeader("Authori-zation", "Bearer " + APP_TOKEN);
        Request request = RequestBuilder.build();

        final Call call = okHttpClient.newCall(request);
        //异步get请求
        call.enqueue(new Callback() {
                         @Override
                         public void onFailure(Call call, IOException e) {
                             connectListener.connectFailed(e.toString());
                             UtilsLog.error("错误", e.toString());
                         }

                         @Override
                         public void onResponse(Call call, Response response) throws IOException {
                             String result = response.body().string();
                             connectListener.connectSuccess(result);
                             UtilsLog.error("成功", result);
                         }
                     }
        );
    }

    private void popupWindow(int flat) {
        yearPopupWindow = new ShopCarPopupWindow(this, R.layout.datepicker);


        datePicker = (DatePicker) findViewById(R.id.datePickerView);
        //获取当前日期
        calendar = Calendar.getInstance();
        year = calendar.get(Calendar.YEAR);
        month = calendar.get(Calendar.MONTH);
        day = calendar.get(Calendar.DAY_OF_MONTH);
        if (flat == 1) {
            new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker view, int year, int month, int day) {
                    nyr_start = year + "-" + month + "-" + day;
                    kaishishijian.setText(nyr_start);
                    kaishishijian.setTextColor(getResources().getColor(R.color.color_333333));
                }
            }, year, month, day).show(); //后三个参数相当于初始化
        } else {
            new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker view, int year, int month, int day) {
                    nyr_end = year + "-" + month + "-" + day;
                    jieshushijian.setText(nyr_end);
                    jieshushijian.setTextColor(getResources().getColor(R.color.color_333333));
                }
            }, year, month, day).show(); //后三个参数相当于初始化
        }


    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}